package rsj.api.orgp;

import com.rlyy.aibase.db.Dbink;
import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.ThinkException;
import common.util.BoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.db.PostgresqlConn;
import rsj.log.ModuleEnum;
import rsj.log.OperationLog;
import rsj.log.OperationTypeEnum;
import rsj.service.OrgpService;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 充值接口
 *
 * @author han_d
 */
@RestController
public class RechargeInsert extends BaseLink {

    @Autowired
    private OrgpService orgpInfoService;

    @RequestMapping(value = "rsj_prod_rechargeInsert")
    @OperationLog(description = "充值维护", logType = OperationTypeEnum.ADD, logModule = ModuleEnum.OPERATIONAL_WORK_PLATFORM)
    public Box executeLink(Box in) throws ThinkException {

        MapNode data = in.getMapNode("data");

        Connection conn = PostgresqlConn.getConnection();
        try {
            orgpInfoService.orgpInsert(conn, data);
        } catch (SQLException e) {
            logger.error("invoke--->" + in.getApi() + " error "
                    + ", arguments is " + in.toJson(), e);
            //return BoxUtil.errorBox(in,  "错误原因::" + e.getMessage());
            return BoxUtil.errorBox(in, "服务器忙！");
        } finally {
            Dbink.close(conn);
        }


        return BoxUtil.successBox(in, "充值成功！");
    }

}
